/**
 * 用户相关类型定义
 */

// 用户信息类型
export interface UserInfo {
  id: number
  username: string
  email: string
  phone?: string
  avatar?: string
  nickname?: string
  realName?: string
  gender?: 'male' | 'female' | 'unknown'
  birthday?: string
  address?: string
  bio?: string
  status: 'active' | 'inactive' | 'banned'
  roles: string[]
  permissions: string[]
  createdAt: string
  updatedAt: string
  lastLoginAt?: string
  lastLoginIp?: string
}

// 用户登录信息类型
export interface LoginInfo {
  token: string
  refreshToken: string
  expires: number
  tokenType: string
  user: UserInfo
}

// 用户注册信息类型
export interface RegisterInfo {
  username: string
  email: string
  password: string
  confirmPassword: string
  phone?: string
  captcha?: string
  agreement: boolean
}

// 用户个人资料类型
export interface UserProfile {
  id: number
  username: string
  email: string
  phone?: string
  avatar?: string
  nickname?: string
  realName?: string
  gender?: 'male' | 'female' | 'unknown'
  birthday?: string
  address?: string
  bio?: string
  settings: UserSettings
  statistics: UserStatistics
}

// 用户设置类型
export interface UserSettings {
  theme: 'light' | 'dark' | 'auto'
  language: 'zh-CN' | 'en-US'
  timezone: string
  notifications: {
    email: boolean
    sms: boolean
    push: boolean
    marketing: boolean
  }
  privacy: {
    profileVisible: boolean
    contactVisible: boolean
    activityVisible: boolean
  }
  security: {
    twoFactorEnabled: boolean
    passwordExpiry: number
    sessionTimeout: number
  }
}

// 用户统计信息类型
export interface UserStatistics {
  loginCount: number
  lastLoginAt: string
  totalOnlineTime: number
  averageOnlineTime: number
  activityScore: number
  achievementCount: number
  followersCount: number
  followingCount: number
  postsCount: number
  commentsCount: number
}

// 用户角色类型
export interface UserRole {
  id: number
  name: string
  code: string
  description: string
  level: number
  permissions: string[]
  users: number[]
  createdAt: string
  updatedAt: string
}

// 用户权限类型
export interface UserPermission {
  id: number
  name: string
  code: string
  description: string
  type: 'menu' | 'button' | 'api' | 'data'
  resource: string
  action: string
  effect: 'allow' | 'deny'
  conditions?: Record<string, any>
}

// 用户会话信息类型
export interface UserSession {
  id: string
  userId: number
  deviceId: string
  deviceType: 'desktop' | 'mobile' | 'tablet'
  browser: string
  os: string
  ip: string
  location: string
  userAgent: string
  createdAt: string
  lastActiveAt: string
  expiresAt: string
  isActive: boolean
}

// 用户操作日志类型
export interface UserOperationLog {
  id: number
  userId: number
  action: string
  module: string
  method: string
  params: Record<string, any>
  result: 'success' | 'failure'
  errorMessage?: string
  ip: string
  userAgent: string
  createdAt: string
  duration: number
}

// 用户偏好设置类型
export interface UserPreferences {
  dashboard: {
    layout: 'grid' | 'list'
    widgets: string[]
    refreshInterval: number
  }
  editor: {
    theme: 'light' | 'dark'
    fontSize: number
    fontFamily: string
    tabSize: number
    wordWrap: boolean
  }
  notifications: {
    sound: boolean
    desktop: boolean
    email: boolean
    frequency: 'immediate' | 'daily' | 'weekly'
  }
}

// 用户积分记录类型
export interface UserPointRecord {
  id: number
  userId: number
  type: 'earn' | 'spend' | 'expire'
  amount: number
  balance: number
  reason: string
  source: string
  orderId?: string
  createdAt: string
  expiresAt?: string
}

// 用户等级类型
export interface UserLevel {
  id: number
  name: string
  level: number
  minPoints: number
  maxPoints: number
  color: string
  icon: string
  privileges: string[]
  description: string
}

// 用户成就类型
export interface UserAchievement {
  id: number
  userId: number
  achievementId: number
  name: string
  description: string
  icon: string
  type: 'badge' | 'title' | 'privilege'
  rarity: 'common' | 'rare' | 'epic' | 'legendary'
  progress: number
  maxProgress: number
  unlocked: boolean
  unlockedAt?: string
  displayOrder: number
}

// 用户关注关系类型
export interface UserFollow {
  id: number
  followerId: number
  followingId: number
  follower: UserInfo
  following: UserInfo
  createdAt: string
  status: 'active' | 'blocked'
  mutual: boolean
}

// 用户消息类型
export interface UserMessage {
  id: number
  fromUserId: number
  toUserId: number
  type: 'text' | 'image' | 'file' | 'system'
  content: string
  attachments?: string[]
  read: boolean
  createdAt: string
  updatedAt: string
  deleteAt?: string
  conversationId: string
}

// 用户群组类型
export interface UserGroup {
  id: number
  name: string
  description: string
  type: 'public' | 'private' | 'system'
  avatar?: string
  ownerId: number
  memberCount: number
  maxMembers: number
  permissions: string[]
  settings: {
    allowInvite: boolean
    allowMemberList: boolean
    allowMemberAdd: boolean
    moderationEnabled: boolean
  }
  createdAt: string
  updatedAt: string
}

// 用户群组成员类型
export interface UserGroupMember {
  id: number
  groupId: number
  userId: number
  role: 'owner' | 'admin' | 'member'
  permissions: string[]
  joinedAt: string
  lastActiveAt: string
  user: UserInfo
  group: UserGroup
}

// 用户活动记录类型
export interface UserActivity {
  id: number
  userId: number
  type: 'login' | 'logout' | 'create' | 'update' | 'delete' | 'view'
  action: string
  target: string
  targetId?: number
  description: string
  metadata: Record<string, any>
  ip: string
  userAgent: string
  createdAt: string
}

// 用户验证信息类型
export interface UserVerification {
  id: number
  userId: number
  type: 'email' | 'phone' | 'identity' | 'real_name'
  value: string
  code: string
  verified: boolean
  verifiedAt?: string
  expiresAt: string
  attempts: number
  maxAttempts: number
  createdAt: string
}

// 用户设备类型
export interface UserDevice {
  id: string
  userId: number
  name: string
  type: 'desktop' | 'mobile' | 'tablet'
  os: string
  browser: string
  version: string
  fingerprint: string
  trusted: boolean
  lastActiveAt: string
  createdAt: string
  location?: string
  ip: string
} 